from sqlalchemy import Column, Integer, String
from database.database import Base
from sqlalchemy import Column, DateTime
from datetime import datetime
from sqlalchemy import Column, Integer, String, DateTime
from datetime import datetime
from sqlalchemy.orm import relationship


# 定义数据库模型

class User(Base):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True, index=True)
    created_at = Column(DateTime, default=datetime.now)  # 使用服务器本地时间

    phone = Column(String(20), unique=True, index=True)  # 手机号字段
    email = Column(String(100), unique=True, index=True)
    password = Column(String(255))  # 添加密码字段，用于存储加密后的密码
    username = Column(String(50), unique=True, index=True)  # 添加用户名字段
    
    # 建立与统计表的关系
    stats = relationship("UserStats", back_populates="user")
